cmake_minimum_required(VERSION 3.13)

set(LIBYUV_INCLUDE ${CMAKE_CURRENT_LIST_DIR}
                   ${CMAKE_CURRENT_LIST_DIR}/include 
                   CACHE INTERNAL "Test Str")

set(LIBYUV_LIB_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib)

if(UNIX)
    message("current platform: Linux ")

    set(LIBYUV_LIB
            ${LIBYUV_LIB_PATH}/libyuv.a
            CACHE INTERNAL "Test Str")

elseif(WIN32)
    message("current platform: Windows ")

    if(CMAKE_CL_64)    #CMAKE的内建变量，如果是true，就说明编译器的64位的，自然可以编译64bit的程序
        set(LIBYUV_LIB_PATH ${LIBYUV_LIB_PATH}/x64)
    else()
        set(LIBYUV_LIB_PATH ${LIBYUV_LIB_PATH}/x86)
    endif()

    if(CMAKE_BUILD_TYPE STREQUAL "Debug")
        # 使用 Debug 库
        set(LIBYUV_LIB_PATH ${LIBYUV_LIB_PATH}/debug)
    elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
        # 使用 Release 库
        set(LIBYUV_LIB_PATH ${LIBYUV_LIB_PATH}/release)
    endif()

    set(LIBYUV_LIB
            ${LIBYUV_LIB_PATH}/yuv.lib
            CACHE INTERNAL "Test Str")
endif()

target_include_directories(${PROJECT_NAME} PUBLIC ${LIBYUV_INCLUDE})
target_link_libraries(${PROJECT_NAME} ${LIBYUV_LIB})


####如果报错，将cmake最低版本设置成3.13既可解决#######

### cmake子目录和父目录变量传递方法：
#set(SQLITE3_LIB "children str" CACHE INTERNAL "Test Str") # 子cmake 和父cmake都可以访问
#set(TEST_CHILDREN_PARENT_SCOPE_STR "children str" PARENT_SCOPE) # 只有父cmake可以访问
#
## 子cmake 和父cmake都可以访问
#set(TEST_CHILDREN_ALL_SCOPE_STR  "children str")
#set(TEST_CHILDREN_ALL_SCOPE_STR ${TEST_CHILDREN_ALL_SCOPE_STR} PARENT_SCOPE)